package com.stock.project.system.inventory.service;

import com.stock.common.support.Convert;
import com.stock.project.system.inventory.domain.Inventory;
import com.stock.project.system.inventory.mapper.InventoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 库存 服务层实现
 *
 * @author stock
 * @date 2019-03-14
 */
@Service
public class InventoryServiceImpl implements IInventoryService {
    @Autowired
    private InventoryMapper inventoryMapper;

    /**
     * 查询库存信息
     *
     * @param id 库存ID
     * @return 库存信息
     */
    @Override
    public Inventory selectInventoryById(Integer id) {
        return inventoryMapper.selectInventoryById(id);
    }

    /**
     * 查询库存列表
     *
     * @param inventory 库存信息
     * @return 库存集合
     */
    @Override
    public List<Inventory> selectInventoryList(Inventory inventory) {
        return inventoryMapper.selectInventoryList(inventory);
    }

    /**
     * 新增库存
     *
     * @param inventory 库存信息
     * @return 结果
     */
    @Override
    public int insertInventory(Inventory inventory) {
        inventory.setCreateTime(new Date());
        inventory.setUpdateTime(new Date());
        return inventoryMapper.insertInventory(inventory);
    }

    /**
     * 修改库存
     *
     * @param inventory 库存信息
     * @return 结果
     */
    @Override
    public int updateInventory(Inventory inventory) {
        inventory.setUpdateTime(new Date());
        return inventoryMapper.updateInventory(inventory);
    }

    /**
     * 删除库存对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteInventoryByIds(String ids) {
        return inventoryMapper.deleteInventoryByIds(Convert.toStrArray(ids));
    }

}
